package list;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * https://blog.csdn.net/qq_40703471/article/details/124111756
 */
public class RemoveElements {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.substring(1, s.length() - 1).split(",");
        int[] nums = new int[split.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(split[i]);
        }
        int target = sc.nextInt();
        ListNode head = getListFromArray(nums);
        ListNode list = removeElements(head, target);

        ArrayList arr = new ArrayList();
        if (list == null) {
            System.out.println("[]");
        }
        while (list != null) {
//            System.out.println(list.val);
            arr.add(list.val);
            list = list.next;
        }
        System.out.println(arr.toString());

    }
    public static ListNode removeElements(ListNode head, int val) {
        ListNode pre = new ListNode(-1);
        pre.next = head;
        ListNode cur = pre;
        while (cur.next != null) {
            if (cur.next.val == val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return pre.next;
    }
    public static ListNode getListFromArray(int[] nums) {
        ListNode listNode = new ListNode();
        ListNode res = listNode;
        for (int num : nums) {
            listNode.next = new ListNode(num);
            listNode = listNode.next;
        }
        return res.next;
    }
}

